package com.gdth.service.listener.impl;

import com.gdth.service.BaseAction;

import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class AppLocationListener implements LocationListener{
	private Service mService;

	private LocationManager locationManager;
	public AppLocationListener(LocationManager locationManager, Service mService){
		this.locationManager = locationManager;
		this.mService = mService;
	}
	
	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub
		//通知Activity  
        Intent intent = new Intent();  
        intent.setAction(BaseAction.LOCATION_ACTION);  
        intent.putExtra(BaseAction.LOCATION, location.toString());  
        mService.sendBroadcast(intent);  
  
        // 如果只是需要定位一次，这里就移除监听，停掉服务。如果要进行实时定位，可以在退出应用或者其他时刻停掉定位服务。  
        locationManager.removeUpdates(this);  
        mService.stopSelf();
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

}
